package ym.ecrm.core.domain.systemManagement;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import ym.ecrm.core.domain.base.BaseEntity;
import ym.ecrm.core.domain.systemManagement.Authority;

/**
 * 角色类
 * @author Princess
 * @version 1.0
 */
@Entity
@Table(name = "t_role")
public class Role extends BaseEntity {

	/**
	 * roleCode 角色编号
	 */
	@Column(length = 60)
	private String roleCode;
	/**
	 * roleName 角色名称
	 */
	@Column(length = 60)
	private String roleName;
	/**
	 * builtIn 是否为内置，Guest为系统内置角色，不可删除
	 */
	private Boolean builtIn;

	@ManyToMany(targetEntity = User.class, 
			cascade = { CascadeType.PERSIST,
			CascadeType.MERGE }, mappedBy = "roles")
	private Set<User> users = new HashSet<User>();
	
	@ManyToMany(targetEntity = Authority.class, 
			fetch=FetchType.EAGER,
			cascade = {CascadeType.PERSIST,
		CascadeType.MERGE})
	@JoinTable(name = "tr_role_authority", 
			joinColumns = @JoinColumn(name = "roleId"), 
			inverseJoinColumns = @JoinColumn(name = "authorityId"))
	private Set<Authority> authorities = new HashSet<Authority>();

	public Set<Authority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set<Authority> authorities) {
		this.authorities = authorities;
	}

	public String getRoleCode() {
		return roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	

	public Boolean getBuiltIn() {
		return builtIn;
	}

	public void setBuiltIn(Boolean builtIn) {
		this.builtIn = builtIn;
	}

	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

}
